<?php
    class UsersController extends AppController{
        var $name = 'Users';
        var $components = array('Auth' , 'Session');
        
        function beforeFilter() {
            parent::beforeFilter();
            $this->Auth->allow('index');
        }
        function index(){
            $this->set('users' ,$this->User->find('all'));
        } 
        function add(){
            if(!empty($this->data)){
                if($this->User->save($this->data)){
                    $this->Sessoin->setFlash('OK');
                    $this->redirect(array('action' => 'index'));
                }
            }
        }
        function view($id){
            $this->User->id = $id;
            $this->set('user' , $this->User->read());
            
        }
        function edit($id = null){
            $this->User->id = $id;
            if(empty($this->data)){
                $this->data = $this->User->read();
            }
            else if($this->User->save($this->data)){
                $this->Session->setFlash('EDIT');
                $this->redirect(array('action' => 'index'));
            }
        }
        
        function delete($id){
            if($this->User->delete($id)){
                $this->Session->setFlash('DELETE');
                $this->redirect(array('action' => 'index'));
            }
        }
    }
    function login() {
	}
    function logout(){
        $this->Auth->logout();
    }
?>
